var should = require('should');
var sevenLoginHandler = require('../../../app/servers/activity/handler/sevenLoginHandler');
var config = require('../../config');
var mongoConnector = require('../../../app/libs/mongodb/mongoConnector');
var activityModel = require('../../../app/models/activityModel');
var Activity = mongoConnector().model('Activity');
var configUtil = require('../../../app/util/configUtil');
var analyze = require('kc-analyze');

suite('测试sevenLoginHandler', function () {
    setup(function (done) {
        var analyze_config = configUtil.load('analyze');
        var game_config = configUtil.load('game');
        analyze.initialize({
            host: analyze_config.host,
            server_id: game_config.server_id
        });
        done();
    });

    var activity_model;

    setup(function (done) {
        Activity.remove({
            role_id: config.other_role_id
        }, function (err) {
            activityModel.getByRoleId(config.other_role_id, function (err, model) {
                activity_model = model;
                activity_model.continuously_login_days = 5;
                activity_model.save(done);
            });
        });
    });

    suite('reward', function () {
        test('累计登陆奖励1', function (done) {
            var msg = {};
            var session = {};
            session.uid = config.other_role_id;

            var seven_login_handler = new sevenLoginHandler();
            seven_login_handler.reward(msg, session, function (err, res) {
                res.code.should.equal(600); //未提供参数
                done();
            });
        });

        test('累计登陆奖励2', function (done) {
            var msg = {};
            msg.reward_day = 3;
            var session = {};
            session.uid = config.other_role_id;

            var seven_login_handler = new sevenLoginHandler();
            seven_login_handler.reward(msg, session, function (err, res) {
                done();
            });
        });

        test('累计登陆活动列表', function (done) {
            var msg = {};
            var session = {};
            session.uid = config.other_role_id;

            var seven_login_handler = new sevenLoginHandler();
            seven_login_handler.list(msg, session, function (err, res) {
                console.log('result:', res.result);
                done();
            });
        });
    });

    suite('添加累计天数', function () {
        test('登录', function (done) {
            activity_model.addContinuouslyLoginDays();
            activity_model.save(done);
        });
    });
});
